# - 实现斐波那契函数(for循环, while循环)
# - 如果遇到可以转换为`int`类型的参数, 则转换, 否则抛出自定义异常`ParamsTypeError`
class ParamsTypeError(Exception):
    pass


def fib_for(x):
    a, b = 0, 1
    my_r = [a, b]
    try:
        x = int(x)
        if x == 0:
            return [a]
        elif x == 1:
            return [a, b]
        for i in range(x-1):
            a = a + b
            b = a
            a = b
            my_r.append(b)
        return my_r
    except Exception as e:
        raise ParamsTypeError("类型不对,请输入正确的类型")


def fib_while(x):
    a, b = 0, 1
    my_r = [a, b]
    try:
        x = int(x)
        if x == 0:
            return [a]
        elif x == 1:
            return [a, b]
        i = 0
        while i < x-1:
            b = a + b
            a = b
            my_r.append(b)
            i += 1
        return my_r
    except Exception as e:
        raise ParamsTypeError("类型不对,请输入正确的类型")


print(f"斐波那契函数:{fib_for(10)}")
print(f"斐波那契函数:{fib_while(10)}")
print(f"斐波那契函数:{fib_for('10')}")
print(f"斐波那契函数:{fib_while('10')}")

